﻿Imports System.Drawing

Module mdlGlobal
    Public Const c_WidthEditor = 8000
    Public Const c_HeightEditor = 4500
    Public Const c_WidthBlock = 800
    Public Const c_HeightBlock = 450
    Public Const c_WidthPort = 200
    Public Const c_HeightPort = 200
    Public Const c_BorderPort = 2
    Public Const c_ResizeArea = 200
    Public Const c_StepRedraw = 50

    Public ColorBlock As Color = Color.Azure
    Public ColorFocusBlock As Color = Color.Beige
    Public ColorActivator As Color = Color.Red
    Public ColorEvent As Color = Color.Red
    Public ColorInput As Color = Color.Red
    Public ColorOutput As Color = Color.Red
    Public ColorFocusPort As Color = Color.Red
    Public ColorSelectPort As Color = Color.Black

    Public m_Editor As shpEditor
    Public m_ActiveObject As Object
    Public m_ActivePort As Object
    Public m_ZoomX As Double
    Public m_ZoomY As Double

    Public Enum MenuIndex
        inEditorMenu = 0
        inBlockMenu = 1
        inActivatorMenu = 2
        inEventMenu = 3
        inInputMenu = 4
        inOutputMenu = 5
        inConnectorMenu = 6
    End Enum

    Public Enum Angles
        Undef = 0
        Right = 1
        Bottom = 2
        Left = 3
        top = 4
    End Enum

    Public Structure Point
        Public X As Long
        Public Y As Long
    End Structure

    Public Structure DPoint
        Public X As Double
        Public Y As Double
    End Structure

    Public Structure Box
        Public X As Single
        Public Y As Single
        Public W As Single
        Public H As Single
    End Structure

    Public Structure Region
        Public X1 As Single
        Public X2 As Single
        Public Y1 As Single
        Public Y2 As Single
    End Structure

    Public Function Angle(ptr1 As Point, ptr2 As Point, ByRef wid As Single, ByRef hei As Single) As Angles
        wid = ptr2.X - ptr1.X
        hei = ptr2.Y - ptr1.Y
        If ptr2.X = ptr1.X And ptr2.Y = ptr1.Y Then
            Angle = Angles.Undef
        ElseIf ptr2.X = ptr1.X Then
            If ptr2.Y > ptr1.Y Then
                Angle = Angles.Bottom
            Else
                Angle = Angles.top
                hei = -hei
            End If
        ElseIf ptr2.Y = ptr1.Y Then
            If ptr2.X > ptr1.X Then
                Angle = Angles.Right
            Else
                Angle = Angles.Left
                wid = -wid
            End If
        ElseIf wid > 0 And hei > 0 Then
            Angle = -Angles.Right
        ElseIf wid < 0 And hei > 0 Then
            Angle = -Angles.top
            wid = -wid
        ElseIf wid < 0 And hei < 0 Then
            Angle = -Angles.Left
            wid = -wid : hei = -hei
        Else
            Angle = -Angles.Bottom
            hei = -hei
        End If
    End Function

    ' Проверка точки или блока на нахождение в пределах поля
    Public Sub Field(ByRef X As Long, ByRef Y As Long, Optional ByVal wid As Long = 0, Optional ByVal hei As Long = 0)
        If X < c_WidthPort Then
            X = c_WidthPort
        ElseIf X + wid > c_WidthEditor * m_ZoomX - c_WidthPort Then
            X = c_WidthEditor * m_ZoomX - c_WidthPort - wid
        End If
        If Y < c_HeightPort Then
            Y = c_HeightPort
        ElseIf Y + hei > c_HeightEditor * m_ZoomY - c_HeightPort Then
            Y = c_HeightEditor * m_ZoomY - c_HeightPort - hei
        End If
    End Sub
End Module
